package com.yhy.wxzn.wcs.device.rgv.bean;


import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
public class Coord {

    private int x;
    private int y;
    private int z;

    public Coord() {
    }

    public Coord(Lifter lifter) {
        this.x = lifter.getX();
        this.y = lifter.getY();
    }

    public Coord(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Coord(Coord sourceNode) {
        this.x = sourceNode.x;
        this.y = sourceNode.y;
        this.z = sourceNode.z;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null) {
            return false;
        }
        Coord coord = (Coord) o;
        return x == coord.x && y == coord.y && z == coord.z;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y, z);
    }


    /**
     * 判断路径始末两点是否径直, 或为同一个点
     *
     * @param start 起点
     * @param end   终点
     * @return boolean
     */
    public static boolean isStraight(Coord start, Coord end) {
        if (start.getZ() != end.getZ()) return false;
        if (start.getX() == end.getX() || start.getY() == end.getY()) return true;
        return false;
    }


    public static Coord parseCoord(String str){
        Coord coord = null;
        try {
            String[] split = str.substring(1, str.length()-1).split(",");
             coord = new Coord(Integer.parseInt(split[0]),
                    Integer.parseInt(split[1]),
                    Integer.parseInt(split[2]));

        }catch (Exception e){
            String msg = String.format("%s转为节点对象失败原因为：%s", str, e.getMessage());
            log.error(msg);
            throw new RuntimeException(msg);
        }
        return coord;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    @Override
    public String toString() {
        return "(" + x + "," + y + "," + z +")";

    }

}
